<?php
session_start();

#-------------------------------------------------------------------------
/**
 * Assign an value to session var
 * @param string $name
 * @param mixed $value
 */
function sessionSetVar($name, $value){
	$_SESSION[$name] = json_encode($value);
	return true;
}

#-------------------------------------------------------------------------
/**
 * Get the value of a session var
 * @param string $name
 * @param bool $isObject If $isObject = true, this function will return an object
 */
function sessionGetVar($name, $isObject = false){
	$var = ($isObject) ? json_decode($_SESSION[$name]) : json_decode($_SESSION[$name], true);

	if (is_array($var)) {
	  foreach($var as $k=>&$v) {
	    if(!is_array($v)) $v = stripslashes($v);
	  }
	} else {
	  $var = stripslashes($var);
	}
	
	return $var;
}

#-------------------------------------------------------------------------
function sessionDestroyVar($name) {
  unset($_SESSION[$name]);
  
  return true;
}

#-------------------------------------------------------------------------
function sessionGetCurrentScriptName(){
	return str_replace('/', '', $_SERVER['PHP_SELF']);
}

#-------------------------------------------------------------------------
function sessionGetCurrentPageName(){
	return str_replace('.php', '', sessionGetCurrentScriptName());
}